<?php
 
$form = $this->element;

$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');


?>
<form enctype="multipart/form-data" method="post" action="">

	<?php 
	
	/**
     * Translate some form errrors.
     * 
     * @param string $key
     * @param string $error
     * @return string
     */
    function _translate($key, $error)
    {
    	$_translated = array(
			'isEmpty' => 'Поле обязательно для заполнения',
		);
	
    	if (isset($_translated[$key])) {
    		return $_translated[$key];
    	}
    	
    	return $error;
    }
    
    $errors = $form->getMessages();
    foreach ($errors as $key => $error) {
    	if (is_array($error)) {
    		unset($errors[$key]);
    	}

   		if (is_array($error)) {
     		foreach ($error as $k => $v) {
     			$label = $form->getElement($key)->getLabel();
     			$v = _translate($k, $v);
     			$errors[$key][$k] = "$label -- $v";
     		}
    	} else {
    		$errors[$key] = _translate($key, $error);
    	}
    }
    
    if ($errors) {
	    echo "<ul class='errors'>";
	    foreach ($errors as $error) {
	    	if (is_array($error)) {
	    		foreach ($error as $k => $v) {
	    			echo "<li>$v</li>";
	    		}
	    	} else {
	    		echo "<li>$error</li>";
	    	}
	    }
	    echo "</ul>";
    }
	
	
	?>


	<div>
	    <dl class="floater-3">
			<?php echo $form->getElement('ext_ids'); ?>
	    </dl>
	    
	    <dl class="floater-3">
			<?php echo $form->getElement('name'); ?>
	    </dl>
	    
	    <dl class="floater-3">
			<?php echo $form->getElement('has_shop'); ?>
	    </dl>
	    
	    <dl class="floater-3">
			<?php echo $form->getElement('is_delivery'); ?>
	    </dl>
	    
	    <dl class="floater-3">
			<?php echo $form->getElement('maincity_id'); ?>
	    </dl>
	    
	    <dl class="floater-3">
			<?php echo $form->getElement('name_where'); ?>
	    </dl>
	    <br>
	    <dl class="floater-3">
	    	<b>Страна</b><br>
	    	<select name="country_id" id="country_id">
				<?php 
				 
				 $countryRows = CountriesPeer::getInstance()->findByName('Россия');
				 echo '<option value="'.$countryRows[0]->getId().'">'.$countryRows[0]->getName().'</option>';
				?>
				</select>
	    </dl>
	    <br>
	    <dl class="floater-3">
	    	<b>Регион*</b><br>
	    	<select name="region_id" id="region_id">
				<?php 
				 $regionsRows = RegionsPeer::getInstance()->findByCountryId($countryRows[0]->getId());
				 echo '<option value="" </option>';
				 foreach($regionsRows as $rRow){
				 	 $selected='';
				 	 if(!empty($id) && $rRow->getId()==$form->getRow()->getRegionId())
				 	 	$selected=' selected';
					 echo '<option value="'.$rRow->getId().'"'.$selected.'>'.$rRow->getName().'</option>';
				 }			
				?>
				</select>
	    </dl>
	    
	    
	    
		<dt id="submit-label">&nbsp;</dt>
		<dd id="submit-element">
			<input type="submit" name="submit" id="submit" value="Сохранить" />
		</dd>
	</div>
</form>